Skip to content

Sort node readiness label keys when generating node affinity - #3212

Open
yuminn-k wants to merge 1 commit into
zalando:masterfrom
yuminn-k:fix-node-readiness-label-order
Open

yuminn-k wants to merge 1 commit into
zalando:masterfrom
yuminn-k:fix-node-readiness-label-order

Conversation

@yuminn-k

@yuminn-k yuminn-k commented Nov 1, 2026 •

Copy link
Copy Markdown

Problem description

nodeAffinity() builds the match expressions for node_readiness_label by ranging over the map, so the order changes from one call to the next. With two or more labels the generated affinity often differs from the one in the running statefulset. compareStatefulSetWith compares the two with reflect.DeepEqual, reports "new statefulset's pod affinity does not match the current one" and replaces the statefulset. The pods roll and the master switches over on every sync.

This change sorts the keys before building the match expressions, so the output is the same on every call. The pooler deployment and the logical backup job call the same function, so they get the fix too.

TestNodeAffinityReadinessLabelOrder calls nodeAffinity() 20 times with four readiness labels and checks the keys come out sorted every time. It fails on master and passes with this change.

Linked issues

Fixes #2931

Checklist

Thanks for submitting a pull request to the Postgres Operator project.
Please, ensure your contribution matches the following items:

  • Your go code is formatted. Your IDE should do it automatically for you.
  • You have updated generated code when introducing new fields to the acid.zalan.do api package.
  • New configuration options are reflected in CRD validation, helm charts and sample manifests.
  • New functionality is covered by unit and/or e2e tests.
  • You have checked existing open PRs for possible overlay and referenced them.

AI disclosure: Written with Claude Code (Claude Opus 5.5)

🤖 Generated with Claude Code

Iterating over the node_readiness_label map produced the match expressions
in random order. With two or more labels the generated affinity differed
from the one in the running statefulset on every sync, so the operator kept
replacing the statefulset and rolling the pods.

Signed-off-by: YuMin Kim <yuminkim.dev@gmail.com>
@FxKu FxKu added the bugfix label Nov 10, 2026
@FxKu FxKu added this to the 2.1.0 milestone Nov 10, 2026
@FxKu FxKu moved this to Waiting for review in Postgres Operator Nov 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Waiting for review

Development

Successfully merging this pull request may close these issues.

Multiple labels in node_readiness_label & empty postgresql spec nodeAffinity triggers a perma-diff in cluster statefulset

2 participants